<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>修改Bug</title>
    <base href="<%=basePath%>"/>
    <link rel="stylesheet" type="text/css" href="css/common.css" />
    <link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
    <script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
    <link rel="stylesheet" href="<%=basePath%>/js/uploadify/css/uploadify.css" type="text/css"></link>
    <script type="text/javascript" src="<%=basePath%>/js/uploadify/jquery.uploadify-3.1.min.js"></script>
    <link rel="stylesheet" href="<%=basePath%>/js/lightbox/css/lightbox.css" type="text/css" />
    <script type="text/javascript" src="<%=basePath%>/js/lightbox/jquery.lightbox.js"></script>
    <style type="text/css">
  		fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
  		form label {font-weight:bold;}
    	table{margin:10px 10px};
  		td{line-height: 40px;}
		input[type="text"]{width:250px;}
		input[type="password"]{width:250px;}
		input[type="textarea"]{width:250px;}   		
    </style>
	<script type="text/javascript">
	  var bugId = null;  
	  $(document).ready(function(){
		     $.ajaxSetup ({ cache:false,async: false });
			 $("#moduleId").mcDropdown("#categorymenu",{ dropShadow: false, targetColumnSize: 1, lineHeight:30, allowParentSelect:true});
		     //异步提交表单
		     var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
		     $("#bugForm").submit(function(){
		         $(this).ajaxSubmit(options);
		          return false;
		     });   
		   
	         //文件上传组件
		     $("#file_upload").uploadify({   
                  'height'        : 27,    
		          'width'         : 80,     
		          'buttonText'    : '添加附件',   
		          'removeCompleted': true,          //上传完毕上传列表是否去除 
		          'fileSizeLimit': '50MB',          //上传文件大小设置 单位可以是B、KB、MB、GB 
	              'swf'           : '<%=basePath%>/js/uploadify/uploadify.swf',   
		          'uploader'      : '<%=basePath%>soft/bug/upload.do',   
		          'auto'          : false,   
		          'formData'      : {'bugId':''},  
		          'fileTypeExts'  : '*.*',   
		          'onUploadStart' : function(file) {   
		                $("#file_upload").uploadify("settings","formData", {'bugId':bugId});   
		           },   
		          'onUploadSuccess':function(file, data, response){ 
		        	  $('#' + file.id).find('.data').html(' 上传完毕');
		        	  location.reload();
		           },   
		          'onUploadComplete':function(file){   
		                $('#importLispDialog').window('close');   
		           },   
		          'onSelectError' : function (file, errorCode, errorMsg) {
		            	if(errorCode == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE)
		            		this.queueData.errorMsg = "不能传空文件!";
		           }
		      });  
	         
		      $(".lightbox").lightbox({
					fitToScreen : true,
					scaleImages : true,
					xScale : 1.2,
					fileLoadingImage : '<%=basePath%>/js/lightbox/images/loading.gif', //加载时图片
					fileBottomNavCloseImage : '<%=basePath%>/js/lightbox/images/closelabel.gif', //关闭图片
					yScale : 1.2
			  });
	   });
	 
	   //提交前验证
	   function beforeSubmit() {
		     if(isEmpty($("#title").val())) { alert("摘要不能为空！"); return false; }
		     if(isEmpty($("#expurgator").val())) { alert("修订人不能为空！"); return false; }
		     return true;
	   }
	
	   function process(responseJson) {
	     if(responseJson.code == 0) {
	         $('#error_label').text("错误信息：" + responseJson.message);
	         $("#p_error").show();
	         return;
	     }
	     else
	     {      
       		 var qs = $("#qs").val();
      	     location.href = "<%=basePath%>soft/bug/list.do?" + qs;
	     }
	   }  
	   function startUpload(){   
		  bugId = $("#bugId").val();
		  if(bugId.replace(/\s/g,'') == '')
		  {
			  alert("bug不能为空！");   
              return false;    
		  }else
	      {
			  $('#file_upload').uploadify('upload','*');   
	      }
	   }   
       
	   //删除文件
	   function del(row,id,path) {
			if(confirm("确定删除该文件吗？")) {
				$.get("<%=basePath%>soft/bug/deleteFile.do", {id:id,path:path}, function(data) {
					var result = $.parseJSON(data);
					if(result.code == 1) {
						delRow(row);
					} else {
						alert(result.msg);
					}
				});
			}
	   }
	   
	   //删除行
	   function delRow(row)   
	   {   
		    $(row).parent("td").parent("tr").remove();   
	   }  
	   
	   //返回列表页面
	   function btn_return(){
		     var qs = $("#qs").val();
    	     location.href = "<%=basePath%>soft/bug/list.do?" + qs;
	   }
	</script>    
  </head>
  <body>
  <div>
    <fieldset>
      <legend>修改Bug：</legend>
      <form id="bugForm" method="post" action="soft/bug/edit.do">
        <input id="qs" name="qs" type="hidden" value="${qs}"/>
        <input type="hidden" name="id" value="${bug.id}" />
        <p id = "p_error" style = "margin:10px 10px;">
            <label id="error_label" style="color:red;"></label>
        </p>
        <table>
            <tr>
			    <td><label for="project">所属项目：</label>
			         <input type="hidden" name="bugId" id="bugId" value="${bug.id}">
			         <input type="hidden" name="projectId" value="${project.id}">
			    </td>
			    <td><input type="text"  value="${project.name}" disabled="disabled" /></td>
		    </tr>
            <tr>
				<td><label for="title">摘要：</label></td>
				<td><input type="text" name="title" id="title"  <c:if test="${sessionScope.username != bug.subEnname}">disabled="disabled"</c:if> value="${bug.title}" />
				<font color="red">&nbsp;*&nbsp;&nbsp;</font>
				</td>
			</tr>
			<tr>
			    <td><label for="expurgator">填写人：</label></td>
				<td><input type="text" disabled="disabled" value="${bug.subCnname}"/></td>
			</tr>
			<tr>
				<td><label for="moduleId">模块：</label></td>
				<td>
				 <input type="text" name="moduleId" id="moduleId"  <c:if test="${sessionScope.username != bug.subEnname}">disabled="disabled"</c:if>  value ="${bug.moduleId}" defaultValue="${bug.moduleId}"/>
                 <ul id="categorymenu" class="mcdropdown_menu" >
			        <c:forEach items="${treeList}" var="tree" varStatus="status">
			            ${tree}
			        </c:forEach>
		         </ul>  	
				</td>
			</tr>
			
			<tr>
			    <td><label for="expurgator">修订人：</label></td>
				<td>
				   <select name="expurgator" id="expurgator"   <c:if test="${sessionScope.username != bug.subEnname}">disabled="disabled"</c:if> style="width:206px;" >
				     <c:forEach items="${userList}" var="u" >
				            <option value="${u.enname}"  <c:if test="${u.enname == bug.expurgator}">selected="selected"</c:if> ><c:out value="${u.cnname}"/></option>
				     </c:forEach>
				   </select>
				</td>
			</tr>
			<tr>
				<td><label for="bugLevel">级别：</label></td>
				<td>
				    <select name="bugLevel" id="bugLevel"  <c:if test="${sessionScope.username != bug.subEnname}">disabled="disabled"</c:if>  style="width:206px;">
						<c:forEach items="${bugLevelList}" var="bl">
					      <option value="${bl.value}"  <c:if test="${bl.value == bug.bugLevel}">selected</c:if>> ${bl.name}</option>
					  	</c:forEach>
				    </select>
				<font color="red">&nbsp;*&nbsp;&nbsp;</font>
				</td>
			</tr>
			<tr>
				<td><label for="status">状态：</label></td>
				<td>
				    <select  name="status"  style="width:206px;" >
		                 <c:forEach items="${bugStatusList}" var="bs">
				            <c:if test="${bs.value == bug.status}">
                               	 <option value="${bs.value}"> ${bs.name}</option>
				            </c:if>
					     </c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td valign="top"><label for="description">Bug描述：</label></td>
				<td valign="top"><textarea  <c:if test="${sessionScope.username != bug.subEnname}">disabled="disabled"</c:if> name="description" id="description" cols="40" rows="8"><c:out value="${bug.description}"></c:out></textarea> <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
			</tr>
			<tr>
				<td></td>
				<td>
				    <input type="submit" id="btn_insert" value="提交" style="width: 80px;" <c:if test="${sessionScope.username != bug.subEnname}">disabled="disabled"</c:if>/>
				    <input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width: 80px;" />
				</td>
			</tr>
        </table>
      </form>
    </fieldset>
   </div>    
   <div id="uploadDiv" >
		<fieldset>
		   <legend>上传附件：</legend>
		   <input type="file" name="uploadify" id="file_upload" />   
		   <hr>   
           <a onclick="startUpload();" href="javascript:void(0);">开始上传</a>    
           <a href="javascript:$('#file_upload').uploadify('cancel', '*')" >取消所有上传</a>   
        </fieldset>
   </div>
   <div>
		<fieldset>
		   <legend>已上传文件：</legend>
			<table id="fileTable" width="900" style="border-top:dashed 1px #ddd; border-bottom: dashed 1px #ddd;" >
			  <tr>
			    <th>文件名</th>
			    <th>上传时间</th>
			    <th>提交人</th>
			    <th colspan="3">操作</th>
			  </tr>
			  <c:forEach items="${attList}" var="att" >
			      <tr align="center" >
				    <td>${att.name}</td>
					<td><fmt:formatDate value="${att.createTime}" type="both"
							dateStyle="medium" timeStyle="medium" /></td>
					<td>${att.uploadUser}</td>
					<td width="40px">
						<a href="<%=basePath%>soft/bug/download.do?fileName=${att.name}&path=${att.path}">
						下载
						</a>
				    <c:if test="${sessionScope.usercnname == att.uploadUser}">
				        <td width="40px"> 
					       <a href="#"  onclick="javascript:del(this,'${att.id}','${att.path}'); return false;">删除</a>	
					    </td>
			        </c:if>
				    <td width="40px">
			          <c:forEach items="${pictureFormatList}" var="pf" >
					       <c:if test="${pf == att.suffix}">
					       <a href="${att.path}" class="lightbox" rel="flowers" title="${att.name}">预览</a>
					       </c:if>
					  </c:forEach>
				   </td>
				  </tr>
			  </c:forEach>
			</table>
        </fieldset>
   </div>
  </body>
</html>